package cn.softcits.thread.even;

import java.util.concurrent.ExecutionException;

/**
 * @author Rocket
 * @version 10.0.1
 * @date 2021-07-04 3:20 PM
 */
public class PrintEven extends Thread {

    private Count count;
    public PrintEven(String name, Count count) {
        this.setName(name);
        this.count = count;
    }
    @Override
    public void run() {
        synchronized (count) {
            while(true) {
                try {
                    Thread.sleep(1000);
                    if(count.getNum() % 2 == 1) {
                        count.wait();
                    } else {
                        System.out.println(Thread.currentThread().getName() + " : " + count.getNum());
                        count.setNum(count.getNum() + 1);
                        count.notify();
                    }



                } catch (Exception e) {

                }

            }
        }


    }
}
